/*
* pps_bom
*/
package com.pitop.project.service;

import com.pitop.core.entity.Page;
import com.pitop.core.exceptions.BaseException;
import com.pitop.core.exceptions.ProjectBomException;
import com.pitop.project.api.ProjectBomFeignApi;
import com.pitop.project.entity.ProjectBom;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 项目bom关联
 *
 * @author berton
 */
@Service("projectBomSVImpl")
@Slf4j
public class ProjectBomSVImpl {

    @Autowired
    private ProjectBomFeignApi projectBomFeignApi;

    /**
     * 加载一个对象ProjectBom
     *
     * @param id * @param projectCode 项目编码* @param bomCode bom编码
     * @return ProjectBom
     */
    public ProjectBom load(Long id, String projectCode, String bomCode) {
        if (id == null && projectCode == null && bomCode == null) {
            throw new ProjectBomException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return projectBomFeignApi.load(id, projectCode, bomCode);
    }

    /**
     * 加载一个对象ProjectBom 通过id,(将查询关联数据)
     *
     * @param id
     * @return ProjectBom
     */
    public ProjectBom loadById(Long id) {
        if (id == null) {
            throw new ProjectBomException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return projectBomFeignApi.loadById(id);
    }

    /**
     * 加载一个对象ProjectBom 通过projectCode,(将查询关联数据)
     *
     * @param projectCode 项目编码
     * @return ProjectBom
     */
    public ProjectBom loadByProjectCode(String projectCode) {
        if (projectCode == null) {
            throw new ProjectBomException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return projectBomFeignApi.loadByProjectCode(projectCode);
    }

    /**
     * 加载一个对象ProjectBom 通过bomCode,(将查询关联数据)
     *
     * @param bomCode bom编码
     * @return ProjectBom
     */
    public ProjectBom loadByBomCode(String bomCode) {
        if (bomCode == null) {
            throw new ProjectBomException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return projectBomFeignApi.loadByBomCode(bomCode);
    }

    /**
     * 加载一个对象ProjectBom,(将查询关联数据)
     *
     * @param id * @param projectCode 项目编码* @param bomCode bom编码
     * @return ProjectBom
     */
    public ProjectBom get(Long id, String projectCode, String bomCode) {
        if (id == null && projectCode == null && bomCode == null) {
            throw new ProjectBomException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return projectBomFeignApi.get(id, projectCode, bomCode);
    }

    /**
     * 加载一个对象ProjectBom 通过id,(将查询关联数据)
     *
     * @param id
     * @return ProjectBom
     */
    public ProjectBom getById(Long id) {
        if (id == null) {
            throw new ProjectBomException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return projectBomFeignApi.getById(id);
    }

    /**
     * 加载一个对象ProjectBom 通过projectCode,(将查询关联数据)
     *
     * @param projectCode 项目编码
     * @return ProjectBom
     */
    public ProjectBom getByProjectCode(String projectCode) {
        if (projectCode == null) {
            throw new ProjectBomException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return projectBomFeignApi.getByProjectCode(projectCode);
    }

    /**
     * 加载一个对象ProjectBom 通过bomCode,(将查询关联数据)
     *
     * @param bomCode bom编码
     * @return ProjectBom
     */
    public ProjectBom getByBomCode(String bomCode) {
        if (bomCode == null) {
            throw new ProjectBomException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return projectBomFeignApi.getByBomCode(bomCode);
    }

    /**
     * 删除对象ProjectBom
     *
     * @param id * @param projectCode 项目编码* @param bomCode bom编码
     */

    public void delete(Long id, String projectCode, String bomCode) {
        if (id == null && projectCode == null && bomCode == null) {
            throw new ProjectBomException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        projectBomFeignApi.delete(id, projectCode, bomCode);
    }

    /**
     * 查询ProjectBom分页
     *
     * @param projectBom 对象
     * @param curPage    当前页
     * @param pageSize   分页条数
     * @return List<ProjectBom>
     */
    public List<ProjectBom> list(ProjectBom projectBom, int curPage, int pageSize) {
        return projectBomFeignApi.list(projectBom, curPage, pageSize);
    }

    /**
     * 查询ProjectBom分页
     *
     * @param id       * @param projectCode  项目编码* @param bomCode  bom编码
     * @param curPage  当前页
     * @param pageSize 分页条数
     * @return List<ProjectBom>
     */
    public List<ProjectBom> list(Long id, String projectCode, String bomCode, int curPage, int pageSize) {
        if (curPage < 0) {
            curPage = 1;
        }

        if (pageSize < 0) {
            pageSize = Page.limit;
        }

        ProjectBom projectBom = new ProjectBom();
        projectBom.setId(id);
        projectBom.setProjectCode(projectCode);
        projectBom.setBomCode(bomCode);

        return projectBomFeignApi.list(projectBom, curPage, pageSize);
    }

    public int count(Long id, String projectCode, String bomCode) {
        return projectBomFeignApi.count(id, projectCode, bomCode);
    }

    public int count(ProjectBom projectBom) {
        return projectBomFeignApi.count(projectBom);
    }

    /**
     * 保存
     *
     * @param projectBom 实体
     * @throws BaseException
     */
    public void save(ProjectBom projectBom) {
        if (projectBom == null) {
            throw new ProjectBomException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        projectBomFeignApi.build(projectBom);
    }

    /**
     * 更新
     *
     * @param projectBom 实体
     * @throws BaseException
     */
    public void modify(ProjectBom projectBom) {
        if (projectBom == null) {
            throw new ProjectBomException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        projectBomFeignApi.modify(projectBom);
    }
}
